<%@ page language="java" import="java.util.*" import="java.sql.*"
	import="javax.servlet.http.HttpSession"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%String userid =request.getParameter("userID"); %>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="blog.anchen8.net" />
<title>毕业生，你的选择</title>
<link rel="stylesheet" type="text/css" href="css/personal.css" />
<script src="js/jQuery1.82.js" type="text/javascript"></script>
<script src="js/jquery.form.js" type="text/javascript"></script>
<script src="js/school.js" type="text/javascript"></script>
<script src="js/home.js" type="text/javascript"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$(".friend").hide();
		$(".applyingfriend").hide();
		$(".modifyinfo").hide();
		$("#error").hide();
		
		$("#modify").click(function(){
			$(".typevalue").hide();
			$(".modifyinfo").show();
		});
		
		$("#cancel").click(function(){
			$(".modifyinfo").hide();
			$(".typevalue").show();
		});
		
		$("#save").click(function(){
			$("#error").hide();
			$.post("ModifyUserinfo",{
				sex:$(".editSex").val(),
				age:$(".editAge").val(),
			    homeprovince:$(".editHome").val(),
			    schoolprovince:$(".editPro").val(),
			    college:$(".editSchool").val(),
			    school:$(".editCol").val(),
			    grade:$(".editClass").val(),
			    description:$(".editDes").val()
			},function(data){
				if(data=="success"){
					window.location.reload();
				}
				if(data=="error"){
					$("#error").show();
				}
			});
		});
		
		$("#apply").click(function() {
			$.post("OperateFriend", {
				Friendid : $("#useridid").val(),
				method : 0
			}, function(data) {
				alert(data);
				if(data=="apply success"){
					window.location.reload();
				}
			});

		});
		
		$(".applicantid").live("click", function(){
			var applicant = $(this).attr("dir");
			$.post("OperateFriend",{
				method:1,
				operate:$(this).attr("title"),
				applicantID:applicant
			},function(data){
				var liID ="#"+applicant;
				if(data=="success"){
					$(""+liID+"").remove();
				}
				if(data=="error"){
					alert("operate error");
				}
			});
		});
		
		$("#myfriend").click(function(){
			$.post("GetFriend",{
				method:0,
				sessionid:$("#sessid").val()
			},function(data){
				$(".friendinfo").remove();
				$(".infolist").hide();
				$(".applyingfriend").hide();
				$(".friend").show();
				var json = data.myfirend;
				for(var i=0;i<(json.length);i++){
					var srcpath = "";
					if(json[i].head==null){
						srcpath = "/Bys-Website/SourceImageFile/100.jpg";
					}else{
						srcpath = "/Bys-Website/USERS/"+json[i].UserID+"/Images/Thumbnail/"+json[i].head;
					}
					var PersonPagePath ="/Bys-Website/PersonMainPage.jsp?userID="+json[i].UserID+"";
;				    $("#showfriend").append("<li class='friendinfo'><a href='"+PersonPagePath+"' target='_blank'><img src='"+srcpath+"'/><span>"+json[i].UserName+"</span></a></li>");
				} 
			},"json");
		});
		
		$("#friendapply").click(function(){
			$.post("GetFriend",{
				method:1,
				sessionid:$("#sessid").val()
			},function(data){
				$(".friendinfo").remove();
				$(".friend").hide();
				$(".infolist").hide();
				$(".applyingfriend").show();
				var json = data.friendapply;
				for(var i=0;i<(json.length);i++){
					var srcpath = "";
					if(json[i].head==null){
						srcpath = "/Bys-Website/SourceImageFile/100.jpg";
					}else{
						srcpath = "/Bys-Website/USERS/"+json[i].myid+"/Images/Thumbnail/"+json[i].head;
					}
					var PersonPagePath ="/Bys-Website/PersonMainPage.jsp?userID="+json[i].myid+"";
;				    $("#showapplyingfriend").append("<li id='"+json[i].myid+"' class='friendinfo'><a href='"+PersonPagePath+"' target='_blank'><img src='"+srcpath+"'/><span>"+json[i].UserName+"</span></a><a  id='accept' class='applicantid' dir='"+json[i].myid+"' title='agree'>同意</a><a id='disagree' class='applicantid' dir='"+json[i].myid+"' title='disagree'>拒绝</a></li>");
				} 
			},"json");
		});
		
		$("#personinfo").click(function(){
			$(".friend").hide();
			$(".applyingfriend").hide();
			$(".infolist").show();
		});
});
        function createMain(){
            var _scrollWidth=Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
            var _scrollHeight=Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
                document.getElementById("main").style.left=(_scrollWidth-950)/2+"px";
               // document.getElementById("m").style.height=_scrollHeight+"px";
        }
        function naviover(val){
            document.getElementById(val).style.backgroundColor="#E1DACF";
        }
        function naviout(val){
            document.getElementById(val).style.backgroundColor="#C5C5C5";
        }
        $(document).ready(function() {
			/*	2nd example	*/
			
			$("#menu2 li a").wrapInner( '<span class="out"></span>' );
			
			$("#menu2 li a").each(function() {
				$( '<span class="over">' +  $(this).text() + '</span>' ).appendTo( this );
			});

			$("#menu2 li a").hover(function() {
				$(".out",	this).stop().animate({'top':	'45px'},	200); // move down - hide
				$(".over",	this).stop().animate({'top':	'0px'},		200); // move down - show

			}, function() {
				$(".out",	this).stop().animate({'top':	'0px'},		200); // move up - show
				$(".over",	this).stop().animate({'top':	'-45px'},	200); // move up - hide
			});

		});
        function uploadPic(UID){
            var msgw,msgh,bordercolor;
            msgw=472;//提示窗口的宽度
            msgh=230;//提示窗口的高度
            titleheight=25 //提示窗口标题高度
            bordercolor="#FF3C00";//提示窗口的边框颜色
            titlecolor="#D2CECE";//提示窗口的标题颜色
            var scrollH=document.body.scrollTop;
    
            var sWidth,sHeight;
            //sWidth=document.body.offsetWidth; //得出当前屏幕的宽
            sWidth=document.body.clientWidth;//BODY对象宽度

            //sHeight=screen.height;//得到当前屏幕的高
            //sHeight=document.body.clientHeight;//BODY对象高度
            if (window.innerHeight && window.scrollMaxY){
                sHeight = window.innerHeight + window.scrollMaxY;
            }
            else if (document.body.scrollHeight > document.body.offsetHeight){
                sHeight = document.body.scrollHeight;
            }else{
                sHeight = document.body.offsetHeight;
            }//以上得到整个屏幕的高

            var bgObj=document.createElement("div");//创建一个div对象
            bgObj.setAttribute('id','bgDiv');//可以用bgObj.id="bgDiv"的方法，是为div指定属性值
            bgObj.style.position="relative";//把bgDiv这个div绝对定位
            bgObj.style.background="#fff";//背景颜色
            bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75)";//ie浏览器透明度设置
            bgObj.style.opacity="0.6";//透明度(火狐浏览器中)
            bgObj.style.marginLeft="0px";//左边为0
            bgObj.style.marginTop="0px";//左边为0
            bgObj.style.width=sWidth + "px";//宽(上面得到的屏幕宽度)
            bgObj.style.height=sHeight + "px";//高(上面得到的屏幕高度)
            bgObj.style.zIndex = "100";//层的z轴位置
            document.body.appendChild(bgObj);
            
            var msgObj=document.createElement("div");//创建一个div对象
            msgObj.setAttribute("id","msgDiv");//可以用bgObj.id="msgDiv"的方法，是为div指定属性值
            msgObj.setAttribute("align","center");//为div的align赋值
            msgObj.style.background="white";//背景颜色为白色
            msgObj.style.border="1px solid #AAA";//边框属性，颜色在上面已经赋值
            msgObj.style.position = "absolute";//绝对定位
            msgObj.style.left = (sWidth-msgw)/2+"px";//从左侧开始位置
            msgObj.style.top = (scrollH+150)+"px";//从上部开始位置
            msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";//字体属性
            //msgObj.style.marginLeft = "-225px";//左外边距
            //msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";//上外边距
            msgObj.style.width = msgw + "px";//提示框的宽(上面定义过)
            msgObj.style.height =msgh + "px";//提示框的高(上面定义过)
            msgObj.style.textAlign = "center";//文本位置属性，居中。
            msgObj.style.lineHeight ="25px";//行间距
            msgObj.style.zIndex = "101";//层的z轴位置
            document.body.appendChild(msgObj);
    		var str="";
    		//var name=document.getElementById('photolist').dir;
    		str+="<form id='modifyhead' action='PersonImage/UploadFile'  method='post' enctype='multipart/form-data'>";
            //msgObj.setAttribute("align","center");//为div的align赋值
           	str+="<h4 id='msgTitle'>上传照片</h4>";
            str+="<div id='selectFile'>";
            str+="相册名称：<input type='text' name='album' readonly='readonly' value='头像相册'>";
            str+="</input>";
            str+="</div>";
            str+="<div id='AlbumName'>";
            str+="选择照片：<input id='imgs' type='file' name='aName' class='Albuminput' multiple/></div>";
            str+="<div id='AlbumDes'>";
            str+="照片描述:<textarea id='des' class='Albumtext' name='description'></textarea></div>";
            str+="<input type='hidden' name='modifyhead' value='modifyhead'>";
            str+="<div id='bottom'><label id='progress'>正在上传...</label>";
            str+=" <input type='button' name='createCancel' value='取消' class='Albumbtn'/>";
            str+="<input  type='submit' name='createOk' value='上传' class='Albumbtn1'/></div>";
            str+="</form>";
            msgObj.innerHTML=str;
            
            bgObj.onclick=function(){
                document.body.removeChild(bgObj);//移除遮罩层
                document.body.removeChild(msgObj);//移除遮罩层
                }
            $(document).ready(function() {
            	$("#progress").hide();
            	$(function (){
            	    var options = {   
            	        success:    function(data){
            	        	$("#des").val("");
            	        	$("#imgs").val("");
            	        	$("#progress").text(data);
            	        	$("#headImage").attr("src","/Bys-Website/USERS/"+UID+"/Images/Thumbnail/"+data+"");
            	        	document.body.removeChild(bgObj);//移除遮罩层
                            document.body.removeChild(msgObj);//移除遮罩层
            	        }  
            	    };  
            	    $('#modifyhead').submit(function(){
            	    	$("#progress").text("正在上传...");
            	    	$("#progress").show();
            	        $(this).ajaxSubmit(options); 
            	        return false;  
            	    });  
            	});            
    	});
        }
    </script>
</head>
<body class="body">
<jsp:useBean id="sql" scope="page" class="com.tzq.JAVABEAN.ConnectDB" />
<jsp:useBean id="getinfo" scope="page" class="com.tzq.JAVABEAN.GetPersonInfo" />
<%String[] ProvinceName = {"北京","天津","河北","山西","内蒙古","辽宁","吉林","黑龙江","江苏","安徽","山东","上海","浙江","江西","福建","湖北","湖南","河南","广东","广西","海南",
		"重庆","四川","贵州","云南","西藏","陕西","甘肃","宁夏","青海","新疆","香港","澳门","台湾"};
%>
<%
String Sessionid = null;
if(session.getAttribute("pid")!=null){
	Sessionid=session.getAttribute("pid").toString();
}
boolean flag = userid.equals(Sessionid);

if(userid==null){%>
<jsp:forward page="/Public/PublicMainPage.jsp"></jsp:forward>
<%}
String[] Userinfo = getinfo.Get(userid);     //得到用户相关信息
int[] addFriend = getinfo.addfriend(Sessionid, userid);
%>
	<div class="main" id="main">

		<span class="title"><%=Userinfo[3] %>的空间</span>
		<div id="menu2" class="menu">
			<ul>
				<li id="info"><a href="/Bys-Website/PersonMainPage.jsp?userID=<%=userid%>">个人信息</a></li>
				<li id="video"><a href="/Bys-Website/PersonVideo/MyVideo.jsp?userid=<%=userid %>">个人视频</a></li>
				<li id="photo"><a href="PersonImage/MyImage.jsp?userid=<%=userid%>">个人相册</a></li>
				<li id="blog"><a href="PersonBlog/MyBlog.jsp?userid=<%=userid%>">个人博客</a></li>
				<li><a href="javascript:;">Contacts</a></li>
			</ul>
		</div>
		<div id="infode">
			<div class="infotitle">&nbsp;个人信息</div>
			<div class="avatar">
				<div class="avatartop">
				<%if(Userinfo[12]==null){ %>
					<img id="headImage" src="/Bys-Website/SourceImageFile/100.jpg" />
				<%}else{ %>
				    <img id="headImage" src="/Bys-Website/USERS/<%=userid %>/Images/Thumbnail/<%=Userinfo[12] %>">
				<%} %>
				</div>
				<%if(flag){ %>
				<div class="editavatar">
					<a href="#" onclick="uploadPic(<%=userid %>)">编辑头像</a>
				</div>
				<%}%>
				<div class="numlist">
					<ul>
						<li>视频：&nbsp;&nbsp;<a href="#"><%=Userinfo[0] %></a></li>
						<li>照片：&nbsp;&nbsp;<a href="#"><%=Userinfo[1] %></a></li>
						<li>博客：&nbsp;&nbsp;<a href="#"><%=Userinfo[2] %></a></li>
					</ul>
				</div>
				<%if(flag){ %>
				<div class="subNavi">
				<ul>
				    <li><a id="personinfo">基本资料</a></li>
				    <li><a id="myfriend">我的好友</a></li>
				    <li><a id="friendapply">好友申请</a></li>
				</ul>
				</div>
				<%}else{ 
				      if(addFriend[0]==0&&addFriend[1]==0){%>
				<div class="makeFri">
				<ul>
				    <li><a id="apply">加为好友</a></li>
				</ul>
				</div>
				     <%}
				      if(addFriend[1]==1){%>
				<div class="subNavi">
				    已发送好友申请
				</div>
				     <%}
				} %>
			</div>
			<div class="infolist">
				<div class="fenge">
					<div class="fengetitle">基本资料</div>
					<%if(flag){ %>
					<div class="infoedit">
						<a id="modify" href="#">编辑</a>
					</div>
					<%} %>
				</div>
				<div class="litype">
					<ul>
						<li>昵称：</li>
						<li>性别：</li>
						<li>年龄：</li>
						<li>家乡：</li>
						<li>学校所在地：</li>
						<li>学校：</li>
						<li>学院：</li>
						<li>入学年份：</li>
						<li>邮箱：</li>
						<li>个性签名：</li>
					</ul>
				</div>
				<div class="typevalue">
					<ul>
						<li><%=Userinfo[3] %></li>
						<li><%=Userinfo[6] %></li>
						<li><%=Userinfo[7] %></li>
						<li><%=ProvinceName[Integer.parseInt(Userinfo[4])] %></li>
						<li><%=ProvinceName[Integer.parseInt(Userinfo[8])]%></li>
						<li><%=Userinfo[10] %></li>
						<li><%=Userinfo[9] %></li>
						<li><%=Userinfo[5] %></li>
						<li><%=Userinfo[11] %></li>
						<li><%=Userinfo[13] %></li>
					</ul>
				</div>
				<%if(flag){ %>
				<div class="modifyinfo">
				    <ul>
				        <li><input readonly="readonly" value="<%=Userinfo[3] %>" class="editName"/></li>
                        <li>
                           <%if(Userinfo[6].equals("男")){ %>
                           <input type="radio" name="RegistSex" value="男" class="editSex" checked="checked"/>男
                        	<input type="radio" name="RegistSex" value="女"  class="editSex"/>女
                           <%}else{ %>
                           <input type="radio" id="sex" value="男" class="editSex"/>男
                           <input type="radio" id="sex" value="女" checked="checked" class="editSex"/>女
                           <%} %>
                        </li>
                        <li>
                           <input type="text" value="<%=Userinfo[7] %>" class="editAge"/>
                        </li>
                        <li>
                           <select id="home" name="HomeProvince" class="editHome">
                                <option value="">--选择省份--</option>
                            	<script>listHome()</script>
                           </select>
                        </li>
                        <li class="listPro">
                            <select onchange="selectSchool(this)" id="province" name="RegistProvince" class="editPro">
                            	<option value="">--选择省份--</option>
                                <script>listPro()</script>
                            </select>
                        </li>
                        
                        <li class="listPro">
                            <select id="city" name="RegistCollege" class="editCol">
                        	    <option>--选择学校--</option>
                            </select>
                        </li>
                        <li class="listPro">
                            <select  name="RegistSchool" class="editSchool">
                                <option>软件学院</option>
                                <option>计算机学院</option>
                                <option>通信学院</option>
                            </select>
                        </li>
                        <li>
                           <select id="home" name="RegistGrade" class="editClass">
                               <option><%=Userinfo[5] %></option>
                               <option>2004</option>
                               <option>2005</option>
                               <option>2006</option>
                               <option>2007</option>
                               <option>2008</option>
                               <option>2009</option>
                               <option>2010</option>
                               <option>2011</option>
                               <option>2012</option>
                           </select>
                        </li>
                        <li><input readonly="readonly" value="<%=Userinfo[11] %>" class="editMail"/></li>
                        <li>
                            <textarea rows="" cols="" id="descipt" class="editDes"><%=Userinfo[13] %></textarea>
                        </li>
                        <li id="editBtn"><input type="button" id="save" value="保存" class="editBtn"><input type="button" id="cancel" value="取消" class="editBtn"></li>
                        <li><label id="error">保存发生错误</label> </li>
   				    </ul>
				</div>
				<%} %>
			</div>
			<div class="friend">
			    <div class="fenge">
			       <div class="fengetitle">我的好友</div>
			    </div>
				<ul id="showfriend">
				</ul>
		    </div>
		    <div class="applyingfriend">
			    <div class="fenge">
			       <div class="fengetitle">好友申请</div>
			    </div>
				<ul id="showapplyingfriend">
				</ul>
		    </div>
		</div>
	</div>
	<script>    
        createMain();
    </script>
	<div class="topbar">
		<div class="logo">
			<img src="/Bys-Website/SourceImageFile/toplogo.jpg" />
		</div>
		<div class="navi">
			<ul class="naviul">
				<li><a href="video.html" class="outli">视频</a></li>
				<li><a href="Public/Photo.jsp" class="outli">相册</a></li>
				<li><a href="Public/Blog.jsp" class="inli">博客</a></li>
			</ul>
		</div>
		<div class="loginfo">
			<ul class="loginfoul">
			<%if(session.getAttribute("pid")==null){%>
				<li><a href="/Bys-Website/Log_in.jsp">登录</a></li>
				<li><a href="/Bys-Website/Regist.jsp">注册</a></li>
			<%}else{%>
				<li><a href="PersonMainPage.jsp?userID=<%=Sessionid  %>"><%=session.getAttribute("username").toString()%></a></li>
				<li><a href="LoginServlet?method=1">退出</a></li>
			<%}%>
			</ul>
		</div>
	</div>
	<input type="hidden" id="useridid" value=<%=userid %>>
	<input type="hidden" id="sessid" value=<%=Sessionid %>>
</body>
</html>